package net.flyinggroup.kafka.domainprocessor;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.streams.kstream.KStream;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.function.Function;

@Configuration
@Slf4j
public class DomainKafkaProcessor {
    @Bean
    public Function<KStream<String, Domain>, KStream<String, Domain>> domainProcessor() {
        return kstream -> kstream.filter((key, value) -> {
            if (value.isDead()) {
                log.info("Inactive domain: {}", value.getDomain());
            } else {
                log.info("Active domain: {}", value.getDomain());
            }
            return !value.isDead();
        });
    }
}
